<?php

namespace app\api\controller;

use app\admin\model\patrol\Inspection;
use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 * 群众举报
 */
class ShopComplaint extends Api
{

    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\ShopComplaint();
        $this->modelShop = new \app\admin\model\shop\User();
        $this->modelCases = new \app\api\model\CasesType();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }


    /**
     * 列表
     * @return void
     */
    public function list()
    {
        $input = input();
        try {
            $pageArr = [
                'page' => 1,
                'page_limit' => 30,
            ];

            $pageArr = array_merge($pageArr, $input);
            $where['user_staff_id'] = $this->auth->getUserinfo()['staff_id'];
            $data = $this->model->where($where)
                ->order('id desc')
                ->where('status' , 3)
                ->field('id,user_shop_id,cases_type_id,image,videofile,content,type')
                ->paginate(['page' => $pageArr['page'] ?: 1, 'list_rows' => $pageArr['page_limit'] ?: 10]);
            foreach ($data->items() as &$v) {
                $v->shop_info = $this->modelShop->where('id',$v->user_shop_id)
                    ->field('name,coverimage,merchant_address,city')->find();
                $v->cases_type_name = $this->modelCases->where('id',$v->cases_type_id)
                    ->value('name');
            }
            $this->success('ok', $data);
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }


}